﻿using System;
using Microsoft.ApplicationBlocks.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;

namespace DataAccess
{
    public class XuatKhoDAO
    {
        private static readonly String URL = ConfigurationSettings.AppSettings["Main.ConnectionString"];
        public XuatKhoDAO()
        {

        }

        public static DataSet GetAll()
        {
            return SqlHelper.ExecuteDataset(URL, CommandType.Text, "SELECT * FROM DonVi");
        }

        public static void Delete(int id) 
        {
            SqlParameter[] sqlParameter = new SqlParameter[1];
            sqlParameter[0] = new SqlParameter("@MaDonVi", id);
            SqlHelper.ExecuteNonQuery(URL, CommandType.Text, "DELETE FROM DonVi WHERE MaDonVi = @MaDonVi", sqlParameter);
        }

        public static void Insert(double tongtien, double thanhtoan, string masanpham,string khachhang, int soluong, double giasanpham, double vat,  string ghichu,string ngayxuat,
            int manhanvien,int hoadon)
        {
            SqlParameter[] sqlParameter = new SqlParameter[11];
            sqlParameter[0] = new SqlParameter("@TongTien", tongtien);
            sqlParameter[1] = new SqlParameter("@ThanhToan", thanhtoan);
            sqlParameter[2] = new SqlParameter("@MaSanPham", masanpham);
            sqlParameter[3] = new SqlParameter("@KhachHang", khachhang);
            sqlParameter[4] = new SqlParameter("@SoLuong", soluong);
            sqlParameter[5] = new SqlParameter("@GiaSanPham", giasanpham);
            sqlParameter[6] = new SqlParameter("@VAT", vat);
            sqlParameter[7] = new SqlParameter("@GhiChu", ghichu);
            sqlParameter[8] = new SqlParameter("@MaNhanVien", manhanvien);
            sqlParameter[9] = new SqlParameter("@NgayXuat", DateUtil.convertStringToDate2(ngayxuat));
            sqlParameter[10] = new SqlParameter("@HoaDon", hoadon);
            SqlHelper.ExecuteNonQuery(URL, CommandType.StoredProcedure, "INSERT_XUAT_KHO", sqlParameter);
        }

        public static void Update(int id,string name,int value)
        {
           
        }
        public static DataSet GetBy(int id)
        {
            SqlParameter[] sqlParameter = new SqlParameter[1];
            sqlParameter[0] = new SqlParameter("@MaXuatKho", id);
            return SqlHelper.ExecuteDataset(URL, CommandType.Text, "SELECT * FROM XuatKho WHERE MaXuatKho = @MaXuatKho", sqlParameter);
        }
    }
}
